Skip to content

Conversation

@yuberee
Copy link
Contributor

@yuberee yuberee commented Nov 26, 2025

Added GetHitboxes and RemoveHitbox to ModelHitboxes
Expose Hitbox's bounds
Thank you

@yuberee
Copy link
Contributor Author

yuberee commented Nov 27, 2025

  • Added summaries
  • Added GetHitbox with overloads for:
    • Bone index
    • Bone name
    • BoneCollection.Bone
    • PhysicsBody
  • Added HitboxesRebuilt action to subscribe to

Having model hitboxes be this accessible allows us to easily target and modify specific ones such as increasing the size of the head hitbox on lower game difficulties or removing hitboxes entirely on "dismembered" enemies.
My other very specific use case was allowing bots to target hitboxes such as the chest and pelvis if they had shotguns.

@aylaylay
Copy link
Contributor

This seems mostly fine to me. I don't like the fact you can add and remove hitboxes but AddHitbox is already public here but that may have been a mistake.

@handsomematt handsomematt added the triaged triaged pull-requests are replicated on the internal sbox repo label Jan 15, 2026
Copilot AI review requested due to automatic review settings January 16, 2026 09:28
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements issue #7718 by exposing hitboxes and their bounds to the public API. It adds methods to retrieve and manipulate hitboxes in ModelHitboxes, exposes the Bounds property on Hitbox, and makes the ModelChanged event public on ModelRenderer.

Changes:

  • Added methods to query hitboxes by bone index, bone, bone name, and physics body
  • Exposed the Bounds property on Hitbox from internal to public
  • Made ModelChanged event on ModelRenderer public with documentation
  • Added HitboxesRebuilt event to notify when hitboxes are rebuilt

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
engine/Sandbox.Engine/Scene/Components/Render/ModelRenderer.cs Made ModelChanged event public and added XML documentation
engine/Sandbox.Engine/Scene/Components/Game/ModelHitboxes.cs Added GetHitboxes, RemoveHitbox, and overloaded GetHitbox methods; added HitboxesRebuilt event; refactored properties to use field keyword
engine/Sandbox.Engine/Scene/Components/Game/Hitbox.cs Changed Bounds property visibility from internal to public

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

GameObject _target;

/// <summary>
/// The target GameObject to report in trace hits. If this is unset we'll defaault to the gameobject on which this component is.
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'defaault' to 'default'.

Suggested change
/// The target GameObject to report in trace hits. If this is unset we'll defaault to the gameobject on which this component is.
/// The target GameObject to report in trace hits. If this is unset we'll default to the gameobject on which this component is.

Copilot uses AI. Check for mistakes.
internal readonly List<Hitbox> Hitboxes = new();

/// <summary>
/// Adds a hitbox to the models hitbox list
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The XML documentation should use possessive form. Change 'models' to 'model's'.

Copilot uses AI. Check for mistakes.
}

/// <summary>
/// Removes a hitbox from the models hitbox list.
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The XML documentation should use possessive form. Change 'models' to 'model's'.

Copilot uses AI. Check for mistakes.
/// <param name="hitbox"></param>
public void RemoveHitbox( Hitbox hitbox )
{
Hitboxes.Remove( hitbox );
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RemoveHitbox does not call Dispose() on the removed hitbox, which could lead to a resource leak. The Hitbox class implements IDisposable and has a Dispose method that removes the PhysicsBody. Consider calling hitbox.Dispose() after removing it from the list, similar to how Clear() handles removal.

Suggested change
Hitboxes.Remove( hitbox );
if ( Hitboxes.Remove( hitbox ) )
{
hitbox?.Dispose();
}

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triaged triaged pull-requests are replicated on the internal sbox repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants